package com.demo.helloworld.config;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

//@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 返回错误信息
     * */
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Map handleException(Exception e){
        HashMap<String, Object> map = new HashMap<>();
        map.put("code", "发生异常");
        map.put("message", e.getMessage());
        return map;
    }
}
